// KVC.cs
//
//  Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//

using System;
using System.Collections;
using System.Collections.Generic;

namespace Whitemice.EOMono
{
  public static class KVC
  {
    public static void TakeValues(this object target, object[] args)
    {      
      if ((args.Length %2) == 0)
      {
        int count = 0;
        var values = new Dictionary<string, object>();
        while (count < args.Length)
        {
          string k = args[count++].ToString();
          object v = args[count++];
          if (values.ContainsKey(k))values[k] = v;
            else values.Add(k, v);
        } // end while
        TakeValues(target, values);
      } else
        {
          throw new Exception("Key-Value set with odd number of values.");
        }
    } // end TakeValues(object[])
    
    public static void TakeValues(this object target, Hashtable args)
    {
      if ((args.Count %2) == 0)
      {
        string k;
        var values = new Dictionary<string, object>();
        foreach(object o in args.Keys)
        {
          k = o.ToString();
          if (values.ContainsKey(k)) values[k] = args[k];
            else values.Add(k, args[k]);
        } // end foreach
        TakeValues(target, values);
      } else 
        {
          throw new Exception("Key-Value set with odd number of valus.");
        }
    } // end TakeValues(Hashtable)
     
    public static void TakeValues(this object target, IDictionary<string, object> args)
    {
      string key;
      
      foreach(string k in args.Keys)
      {
        key = k.ToLower();
        if (key.Contains("."))
        {
        } else
          {
          }
      } // end foreach-key
    } // end TakeValues(IDictionary)
  }
}
